<template>
  <input
    class="hminput"
    type="text"
    @input="handlerinput"
    :class="{success:statu,error:!statu}"
    @change='handlerchange'
  >
</template>

<script>
export default {
  props: {
    rules: {
      type: RegExp,
    },
    msg: {
      type: String,
      default: "输入有误",
    },
  },
  data() {
    return {
      statu: true,
    };
  },
  methods: {
    handlerchange(e) {
      let v = e.target.value;
      if (this.rules) {
        if (!this.rules.test(v)) {
          this.$toast(this.msg);
        }
      }
    },
    handlerinput(e) {
      let v = e.target.value;
      if (this.rules) {
        if (this.rules.test(v)) {
          this.statu = true;
        } else {
          this.statu = false;
        }
      }
      this.$emit("input", v);
    },
  },
};
</script>

<style lang="less" scoped>
.hminput {
  width: 318/360 * 100vw;
  height: 60px;
  outline: none;
  border: none;
  border-bottom: 3px solid #ccc;
  font-size: 20px;
  line-height: 60px;
}
.success {
  border-bottom-color: green;
}
.error {
  border-bottom-color: red;
}
</style>